<script type="text/javascript">
$().ready(function() {
	var $inputFormAjax = $("#inputFormAjax");
	var $subBtn = $('#subBtn');
	var $name = $('#name');
	var $description = $('#description');
	 //表单验证
	$inputFormAjax.validate({
		rules: {
			categoryName:{
				required: true,
				remote:{
					url:"../v_check_category.jspx?exist=true",
					cache:false
				}
			}
		},
		messages: {
			categoryName: {
				remote: "已存在"
			}
		}
	});

	// 邮件测试
	$subBtn.click(function() {
		var $this = $(this);
		function valid(element) {
			return $inputFormAjax.validate().element(element);
		}
		$.ajax({
			url: "../category/o_ajax_save.jspx",
			type: "POST",
			data: {name:$name.val(), description : $description.val()},
			dataType:'json',
			cache: false,
			beforeSend: function() {
				if (valid($name)) {
					$this.prop("disabled", true);
				} else {
					return false;
				}
			},
			success: function(message) {
				$this.prop("disabled", false);
				if(message.type=='success'){
					$('#categoryName').val(message.content);
					$('.xxDialog').remove();
					$('.dialogOverlay').remove();
				}else{
					$.message(message);
				}
			}
		});
	});
});
</script>

<form id="inputFormAjax"  onsubmit="return false">
	<table class="input">
		<tr>
			<th><span class="requiredField">*</span>名称:</th>
			<td><input type="text" name="categoryName" class="text"  id="name" maxlength="100" /></td>
		</tr>
		<tr>
			<th>描述:</th>
			<td><input type="text" name="description" id="description" class="text" maxlength="100" /></td>
		</tr>
		<tr>
			<td colspan="2">&nbsp;</td>
		</tr>
		<tr>
			<th>&nbsp;</th>
			<td>
				<input type="button"  id="subBtn" class="button" value="确&nbsp;&nbsp;定" />
			</td>
		</tr>
	</table>
</form>
